package com.heima.service.impl;

import com.heima.mapper.DeptMapper;
import com.heima.pojo.Dept;
import com.heima.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptMapper deptMapper;

    /**
     * 查询所有部门
     * @return
     */
    @Override
    public List<Dept>queryDepts(){
        List<Dept>deptList= deptMapper.getAll();
        return deptList;
    }

    /**
     * 根据id删除部门
     * @param id
     */
    public void delete(Integer id) {
        deptMapper.delete(id);
    }
@Override
    public void add(Dept dept) {
    //补充上两个时间参数 createTime和updateTime
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.add(dept);
    }

    /**
     * 根据id查部门对象
     * @param id
     */
    @Override
    public Dept getById(Integer id) {
        Dept deId = deptMapper.getById(id);
        return deId;
    }

    /**
     * 修改部门数据为新的dept数据
     * @param dept
     */
    @Override
    public void update(Dept dept) {
        LocalDateTime now = LocalDateTime.now();
        dept.setUpdateTime(now);
        deptMapper.update(dept);
    }
}
